package com.google.gwt.sample.json.client;

//import therandomhomepage.widgets.client.LightboxImage;

import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.ui.*;

public class WorkshopEntry extends EntryPanel{
	//private LightboxImage lightboxImage;
	private HorizontalPanel horizontalPanel_4 = new HorizontalPanel();
	private Hyperlink nextHyperlink;
	private PhotoAlbumClickListener photoClick;
	public WorkshopEntry() {
		super();
		
		final VerticalPanel verticalPanel_4 = new VerticalPanel();
		panel.add(verticalPanel_4);
		verticalPanel_4.setWidth("100%");	

		verticalPanel_4.add(titleLabel);
		titleLabel.setHeight("25px");
		titleLabel.setStyleName("gwt-Label2");

		final VerticalPanel verticalPanel_2 = new VerticalPanel();
		panel.add(verticalPanel_2);
		verticalPanel_2.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		verticalPanel_2.setSize("100%", "200px");

		final Label resourcesLabel = new Label("Resources");
		verticalPanel_2.add(resourcesLabel);
		resourcesLabel.setHeight("25px");
		titleLabel.setStyleName("gwt-Label2");

		verticalPanel_4.add(horizontalPanel_4);
		horizontalPanel_4.setWidth("100%");
		horizontalPanel_4.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);

		horizontalPanel_4.add(richTextArea);
		richTextArea.setWidth("250px");
		richTextArea.setStyleName("gwt-RichTextArea");
		horizontalPanel_4.setCellHorizontalAlignment(richTextArea, HasHorizontalAlignment.ALIGN_LEFT);

//		final Image image = new Image("home.gif");
//		lightboxImage = new LightboxImage(image);
//		horizontalPanel_4.add(lightboxImage);
//		image.setHeight("150px");
		horizontalPanel_4.add(photo);
		photo.setHeight("150px");
		verticalPanel_2.setCellHorizontalAlignment(resourcesLabel, HasHorizontalAlignment.ALIGN_LEFT);
		resourcesLabel.setStyleName("gwt-Label2");
		
		nextHyperlink = new Hyperlink("more photos", "some history token");
		verticalPanel_2.add(nextHyperlink);
		photoClick = new PhotoAlbumClickListener(photo.getUrl());
		nextHyperlink.addClickListener(photoClick);

		verticalPanel_2.setCellWidth(nextHyperlink, "100px");
		verticalPanel_2.setCellHeight(nextHyperlink, "100%");
		verticalPanel_2.setCellVerticalAlignment(nextHyperlink, HasVerticalAlignment.ALIGN_TOP);
		verticalPanel_2.setCellHorizontalAlignment(nextHyperlink, HasHorizontalAlignment.ALIGN_LEFT);

	}
	public void setPanelStyle(String style){
		panel.setStyleName(style);
	}
	public void updateEntry(JSONValue json){
    	final String workshopName = json.isObject().get("title").toString().replaceAll("\"", "");
    	final String imageLoc = json.isObject().get("photoFolder").toString().replaceAll("\"", "");
    	final String desc = json.isObject().get("shortDesc").toString().replaceAll("\"", "");
		titleLabel.setText(workshopName);
		horizontalPanel_4.remove(photo);
		photo = new Image(imageLoc);
		photo.setHeight("150px");
		nextHyperlink.removeClickListener(photoClick);
		photoClick = new PhotoAlbumClickListener(photo.getUrl());
		nextHyperlink.addClickListener(photoClick);
		horizontalPanel_4.add(photo);
		richTextArea.setText(desc);		
	}

	public String searchText() {
		return "/python/workshops?search=";
	}
}
